import SchemaMeta from './schema-meta';
import NodeGenerator from './node-generator';
import type { ChildrenParserConstructorProps, ChildrenParserProps, SourceCode } from '../types';

export default class ChildrenParser extends SchemaMeta implements ChildrenParserProps {
  constructor(props: ChildrenParserConstructorProps) {
    super(props);
  }

  async parse(): Promise<SourceCode['children']> {
    if (Array.isArray(this.schema.children)) {
      return await Promise.all(
        this.schema.children.map(async (schema) => await new NodeGenerator({ schema }).compiler()),
      );
    }
    if (typeof this.schema.children === 'string') {
      return this.schema.children;
    }
  }
}
